package com.danger.Activity.Account;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;
import com.danger.Activity.BackHandledFragment;
import com.danger.Activity.BackHandledInterface;
import com.danger.Activity.R;
import com.danger.Model.bean.UserInfoBean;
import com.danger.MyApplication;
import com.danger.Util.FileCacheService;
import com.danger.Widget.MyCircleImageView;
import cn.bmob.v3.BmobUser;

public class UserInfoActivity extends AppCompatActivity implements BackHandledInterface {

    private BackHandledFragment selectedFragment;
    private Toolbar toolbar;
    private FileCacheService service;
    private TextView personal_info_username;
    private MyCircleImageView personal_info_photo;
    private TextView personal_info_phone;
    private UserInfoBean userInfo;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.getInstance().addActivity(this);
        service = new FileCacheService(this);
        if (service.getSharePreference("setting").get("theme").equals("1")) {
            setContentView(R.layout.activity_user_info);
        } else {
            setContentView(R.layout.fragment_another_user_info_theme);
        }

        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction().add(R.id.user_info_container, new ScrollingUserInfoFragment()).commit();
        }

        initView();
    }

    private void initView() {
        userInfo = BmobUser.getCurrentUser(this, UserInfoBean.class);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        if (!service.getSharePreference("setting").get("theme").equals("1")) {
            personal_info_username = (TextView) findViewById(R.id.personal_info_username);
            personal_info_photo = (MyCircleImageView) findViewById(R.id.personal_info_photo);
            personal_info_phone = (TextView) findViewById(R.id.personal_info_phone);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    public Toolbar getToolbar() {
        return toolbar;
    }

    @Override
    public void onBackPressed() {
        if (selectedFragment == null || !selectedFragment.onBackPressed()) {
            if (getFragmentManager().getBackStackEntryCount() == 0) {
                super.onBackPressed();
            } else {
                getFragmentManager().popBackStack();
            }
        }
    }

    @Override
    public void setSelectedFragment(BackHandledFragment selectedFragment) {
        this.selectedFragment = selectedFragment;
    }

    public TextView getUserNameTexTView() {
        return personal_info_username;
    }

    public TextView getUserPhoneTextView() {
        return personal_info_phone;
    }

    public MyCircleImageView getMyPhotoView() {
        return personal_info_photo;
    }


}
